package demo.common.model;

import java.util.Collections;
import java.util.List;

/**
 * Created by llq on 2017/5/22.
 */
public class PageResult<T>  {

    /**
     * 总记录数
     */
    private int total;

    /**
     * 分页结果List
     */
    private List<T> data = Collections.emptyList();

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public static <T> PageResult<T> from(List<T> list) {
        if(list == null){
            list = Collections.emptyList();
        }

        PageResult<T> result = new PageResult<>();
        result.setTotal(list.size());
        result.setData(list);
        return result;
    }

}
